#include"comm.hpp"

int main()
{
    //1、创建命名管道
    int ret=mkfifo(ipcPath.c_str(),MODE);
    if(ret==-1)
    {
        perror("mkfifo");
        exit(1);
    }

    //2、正常文件操作：通信
    int fd=open(ipcPath.c_str(),O_RDONLY);//只读打开
    if(fd<0)
    {
        perror("open");
        exit(2);
    }
    char buffer[SIZE];
    buffer[0]=0;
    while(true)
    {
        ssize_t s=read(fd,buffer,sizeof(buffer)-1);
        if(s>0)
        {
            buffer[s-1]=0;
            cout<<"client say:"<<buffer<<endl;
        }
        else if(s==0)
        {
            cerr << "read the end of file ->  client quit, server quit too" << endl;
            break;
        }
        else
        {
            perror("read");
            break;
        }
    }
    close(fd);
    return 0;
}